package com.gxuwz.service.impl;

import com.gxuwz.dao.InstructorDao;
import com.gxuwz.entity.Department;
import com.gxuwz.entity.Instructor;
import com.gxuwz.entity.vo.PageVo;
import com.gxuwz.result.PageInfo;
import com.gxuwz.service.InstructorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InstructorServiceImpl implements InstructorService {

    @Autowired
    private InstructorDao instructorDao;


    public PageVo getInstructorList(Instructor instructor, PageInfo pageInfo) {
        if(instructor == null){
            return instructorDao.selectInstructorAll(null,pageInfo);
        }
        String instName = instructor.getInstName();
        String instID = instructor.getInstID();
        String telephone = instructor.getTelephone();
        if( (instName!=null && !instructor.equals("")) || (instID!= null && !instID.equals("")) || (telephone!= null && !telephone.equals(""))){
            return instructorDao.selectInstructorAll(instructor, pageInfo);
        } else {
            return instructorDao.selectInstructorAll(null,pageInfo);
        }
    }

    public Instructor getInstructorOne(String depId) {
        Instructor instructor = instructorDao.selectInstructorByID(depId);
        return instructor;
    }


    public boolean addInstructorInfo(Instructor instructor) {
        int i = instructorDao.insertInstructor(instructor);
        boolean flag = i > 0 ? true : false;
        return flag;
    }


    public boolean updateInstructorInfo(Instructor instructor, String oldId) {
        int i = instructorDao.updateInstructor(instructor,oldId);
        boolean flag = i > 0 ? true : false;
        return flag;
    }


    public boolean deleteInstructorOne(String instId) {
        int i = instructorDao.deleteInstructorById(instId);
        boolean flag = i > 0 ? true : false;
        return flag;
    }

    public List<String> selectInstructorIds() {
        List<String> ids = instructorDao.selectInstructorIds();
        return ids;
    }

    public boolean selectInstructorExist(String depId) {
        List<Department> departments = instructorDao.selectInstructorByDepID(depId);
        if(departments.isEmpty()){
            return true;
        } else {
            return false;
        }
    }

    public String getDepIDByInstID(String instID) {
        String depID = instructorDao.selectDepIDByInstID(instID);
        return depID;
    }

    @Override
    public List<String> selectInstructorIdsNoDel() {
        List<String> strings = instructorDao.selectInstructorIdsNoDel();
        return strings;
    }


}
